package com.nbsaas.boot.controller.user;

import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import com.nbsaas.boot.user.api.apis.UserAccessLogApi;
import com.nbsaas.boot.user.api.domain.request.UserAccessLogRequest;
import com.nbsaas.boot.user.api.domain.request.UserAccessLogSearch;
import com.nbsaas.boot.user.api.domain.response.UserAccessLogResponse;
import com.nbsaas.boot.user.api.domain.simple.UserAccessLogSimple;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 对外控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/userAccessLog")
public class UserAccessLogController {


    @Resource
    private UserAccessLogApi userAccessLogApi;


    @RequestMapping("/search")
    public PageResponse<UserAccessLogSimple> search(UserAccessLogSearch request) {
        return userAccessLogApi.search(request);
    }

    @RequestMapping("/list")
    public ListResponse<UserAccessLogSimple> list(UserAccessLogSearch request) {
        return userAccessLogApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @CreateData
    @RequestMapping("/create")
    public ResponseObject<UserAccessLogResponse> create(@Validated(AddOperator.class) UserAccessLogRequest request) {
        return userAccessLogApi.create(request);
    }

    @UpdateData
    @RequestMapping("/update")
    public ResponseObject<UserAccessLogResponse> update(@Validated(UpdateOperator.class) UserAccessLogRequest request) {
        return userAccessLogApi.update(request);
    }

    @RequestMapping("/delete")
    public ResponseObject<?> delete(@Validated(DeleteOperator.class) UserAccessLogRequest request) {
        return userAccessLogApi.delete(request);
    }

    @RequestMapping("/view")
    public ResponseObject<UserAccessLogResponse> view(@Validated(ViewOperator.class) UserAccessLogRequest request) {
        return userAccessLogApi.view(request);
    }
}